home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-02 | 55.5 KB | 1,401 lines |
- Newsgroups: comp.sources.misc
- From: daveg@synaptics.com (David Gillespie)
- Subject: v24i099: gnucalc - GNU Emacs Calculator, v2.00, Part51/56
- Message-ID: <1991Nov3.001052.19800@sparky.imd.sterling.com>
- X-Md4-Signature: f137f14d9adc4e0fd7629cf3d509f3b6
- Date: Sun, 3 Nov 1991 00:10:52 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: daveg@synaptics.com (David Gillespie)
- Posting-number: Volume 24, Issue 99
- Archive-name: gnucalc/part51
- Environment: Emacs
- Supersedes: gmcalc: Volume 13, Issue 27-45
-
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file calc.texinfo continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 51; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping calc.texinfo'
- else
- echo 'x - continuing file calc.texinfo'
- sed 's/^X//' << 'SHAR_EOF' >> 'calc.texinfo' &&
- stay the same; the top three rows change to a new set of commands.
- To return to earlier menus, click the middle mouse button
- [@code{calc-keypad-menu-back}] or simply advance through the menus
- until you wrap around. Typing @key{TAB} inside the keypad window
- is equivalent to clicking the right mouse button there.
- X
- You can always click the @key{EXEC} button and type any normal
- Calc key sequence. This is equivalent to switching into the
- Calc buffer, typing the keys, then switching back to your
- original buffer.
- X
- @menu
- * Keypad Main Menu::
- * Keypad Functions Menu::
- * Keypad Binary Menu::
- * Keypad Vectors Menu::
- * Keypad Modes Menu::
- @end menu
- X
- @node Keypad Main Menu, Keypad Functions Menu, Keypad Mode, Keypad Mode
- @section Main Menu
- X
- @group
- @smallexample
- |----+-----Calc 2.00-----+----1
- |FLR |CEIL|RND |TRNC|CLN2|FLT |
- |----+----+----+----+----+----|
- | LN |EXP | |ABS |IDIV|MOD |
- |----+----+----+----+----+----|
- |SIN |COS |TAN |SQRT|y^x |1/x |
- |----+----+----+----+----+----|
- | ENTER |+/- |EEX |UNDO| <- |
- |-----+---+-+--+--+-+---++----|
- | INV | 7 | 8 | 9 | / |
- |-----+-----+-----+-----+-----|
- | HYP | 4 | 5 | 6 | * |
- |-----+-----+-----+-----+-----|
- |EXEC | 1 | 2 | 3 | - |
- |-----+-----+-----+-----+-----|
- | OFF | 0 | . | PI | + |
- |-----+-----+-----+-----+-----+
- @end smallexample
- @end group
- X
- @noindent
- This is the menu that appears the first time you start Keypad Mode.
- It will show up in a vertical window on the right side of your screen.
- Above this menu is the traditional Calc stack display. On a 24-line
- screen you will be able to see the top three stack entries.
- X
- The ten digit keys, decimal point, and @key{EEX} key are used for
- entering numbers in the obvious way. @key{EEX} begins entry of an
- exponent in scientific notation. Just as with regular Calc, the
- number is pushed onto the stack as soon as you press @key{ENTER}
- or any other function key.
- X
- The @key{+/-} key corresponds to normal Calc's @kbd{n} key. During
- numeric entry it changes the sign of the number or of the exponent.
- At other times it changes the sign of the number on the top of the
- stack.
- X
- The @key{INV} and @key{HYP} keys modify other keys. As well as
- having the effects described elsewhere in this manual, Keypad Mode
- defines several other ``inverse'' operations. These are described
- below and in the following sections.
- X
- The @key{ENTER} key finishes the current numeric entry, or otherwise
- duplicates the top entry on the stack.
- X
- The @key{UNDO} key undoes the most recent Calc operation.
- @kbd{INV UNDO} is the ``redo'' command, and @kbd{HYP UNDO} is
- ``last arguments'' (@kbd{M-RET}).
- X
- The @key{<-} key acts as a ``backspace'' during numeric entry.
- At other times it removes the top stack entry. @kbd{INV <-}
- clears the entire stack. @kbd{HYP <-} takes an integer from
- the stack, then removes that many additional stack elements.
- X
- The @key{EXEC} key prompts you to enter any keystroke sequence
- that would normally work in Calc mode. This can include a
- numeric prefix if you wish. It is also possible simply to
- switch into the Calc window and type commands in it; there is
- nothing ``magic'' about this window when Keypad Mode is active.
- X
- The other keys in this display perform their obvious calculator
- functions. @key{CLN2} rounds the top-of-stack by temporarily
- reducing the precision by 2 digits. @key{FLT} converts an
- integer or fraction on the top of the stack to floating-point.
- X
- The @key{INV} and @key{HYP} keys combined with several of these keys
- give you access to some common functions even if the appropriate menu
- is not displayed. Obviously you don't need to learn these keys
- unless you find yourself wasting time switching among the menus.
- X
- @table @kbd
- @item INV +/-
- is the same as @key{1/x}.
- @item INV +
- is the same as @key{SQRT}.
- @item INV -
- is the same as @key{CONJ}.
- @item INV *
- is the same as @key{y^x}.
- @item INV /
- is the same as @key{INV y^x} (the @cite{x}th root of @cite{y}).
- @item HYP/INV 1
- are the same as @key{SIN} / @kbd{INV SIN}.
- @item HYP/INV 2
- are the same as @key{COS} / @kbd{INV COS}.
- @item HYP/INV 3
- are the same as @key{TAN} / @kbd{INV TAN}.
- @item INV/HYP 4
- are the same as @key{LN} / @kbd{HYP LN}.
- @item INV/HYP 5
- are the same as @key{EXP} / @kbd{HYP EXP}.
- @item INV 6
- is the same as @key{ABS}.
- @item INV 7
- is the same as @key{RND} (@code{calc-round}).
- @item INV 8
- is the same as @key{CLN2}.
- @item INV 9
- is the same as @key{FLT} (@code{calc-float}).
- @item INV 0
- is the same as @key{IMAG}.
- @item INV .
- is the same as @key{PREC}.
- @item INV ENTER
- is the same as @key{SWAP}.
- @item HYP ENTER
- is the same as @key{RLL3}.
- @item INV HYP ENTER
- is the same as @key{OVER}.
- @item HYP +/-
- packs the top two stack entries as an error form.
- @item HYP EEX
- packs the top two stack entries as a modulo form.
- @item INV EEX
- creates an interval form; this removes an integer which is one
- of 0 @samp{[]}, 1 @samp{[)}, 2 @samp{(]} or 3 @samp{()}, followed
- by the two limits of the interval.
- @end table
- X
- The @kbd{OFF} key turns Calc off; typing @kbd{M-# k} or @kbd{M-# M-#}
- again has the same effect. This is analogous to typing @kbd{q} or
- hitting @kbd{M-# c} again in the normal calculator. If Calc is
- running standalone (the @code{calc-keypad} command appeared in the
- command line that started Emacs), then @kbd{OFF} is replaced with
- @kbd{EXIT}; clicking on this actually exits Emacs itself.
- X
- @node Keypad Functions Menu, Keypad Binary Menu, Keypad Main Menu, Keypad Mode
- @section Functions Menu
- X
- @group
- @smallexample
- |----+----+----+----+----+----2
- |IGAM|BETA|IBET|ERF |BESJ|BESY|
- |----+----+----+----+----+----|
- |IMAG|CONJ| RE |ATN2|RAND|RAGN|
- |----+----+----+----+----+----|
- |GCD |FACT|DFCT|BNOM|PERM|NXTP|
- |----+----+----+----+----+----|
- @end smallexample
- @end group
- X
- @noindent
- This menu provides various operations from the @kbd{f} and @kbd{k}
- prefix keys.
- X
- @key{IMAG} multiplies the number on the stack by the imaginary
- number @cite{i = (0, 1)}.
- X
- @key{RE} extracts the real part a complex number. @kbd{INV RE}
- extracts the imaginary part.
- X
- @key{RAND} takes a number from the top of the stack and computes
- a random number greater than or equal to zero but less than that
- number. (@xref{Random Numbers}.) @key{RAGN} is the ``random
- again'' command; it computes another random number using the
- same limit as last time.
- X
- @key{INV GCD} computes the LCM (least common multiple) function.
- X
- @key{INV FACT} is the gamma function. @c{$\Gamma(x) = (x-1)!$}
- @cite{gamma(x) = (x-1)!}.
- X
- @key{PERM} is the number-of-permutations function, which is on the
- @kbd{H k c} key in normal Calc.
- X
- @key{NXTP} finds the next prime after a number. @kbd{INV NXTP}
- finds the previous prime.
- X
- @node Keypad Binary Menu, Keypad Vectors Menu, Keypad Functions Menu, Keypad Mode
- @section Binary Menu
- X
- @group
- @smallexample
- |----+----+----+----+----+----3
- |AND | OR |XOR |NOT |LSH |RSH |
- |----+----+----+----+----+----|
- |DEC |HEX |OCT |BIN |WSIZ|ARSH|
- |----+----+----+----+----+----|
- | A | B | C | D | E | F |
- |----+----+----+----+----+----|
- @end smallexample
- @end group
- X
- @noindent
- The keys in this menu perform operations on binary integers.
- Note that both logical and arithmetic right-shifts are provided.
- @key{INV LSH} rotates one bit to the left.
- X
- The ``difference'' function (normally on @kbd{b d}) is on @key{INV AND}.
- The ``clip'' function (normally on @kbd{b c}) is on @key{INV NOT}.
- X
- The @key{DEC}, @key{HEX}, @key{OCT}, and @key{BIN} keys select the
- current radix for display and entry of numbers: Decimal, hexadecimal,
- octal, or binary. The six letter keys @key{A} through @key{F} are used
- for entering hexadecimal numbers.
- X
- The @key{WSIZ} key sets the current word size for binary operations.
- The default is 32 bits. You can respond to the prompt using either
- the keyboard or the digits and @key{ENTER} from the keypad. Use
- @key{INV WSIZ} to see the current word size.
- X
- @node Keypad Vectors Menu, Keypad Modes Menu, Keypad Binary Menu, Keypad Mode
- @section Vectors Menu
- X
- @group
- @smallexample
- |----+----+----+----+----+----4
- |SUM |PROD|MAX |MAP*|MAP^|MAP$|
- |----+----+----+----+----+----|
- |MINV|MDET|MTRN|IDNT|CRSS|"x" |
- |----+----+----+----+----+----|
- |PACK|UNPK|INDX|BLD |LEN |... |
- |----+----+----+----+----+----|
- @end smallexample
- @end group
- X
- @noindent
- The keys in this menu operate on vectors and matrices.
- X
- @key{PACK} removes an integer @var{n} from the top of the stack;
- the next @var{n} stack elements are removed and packed into a vector,
- which is replaced onto the stack. Thus the sequence
- @kbd{1 ENTER 3 ENTER 5 ENTER 3 PACK} enters the vector
- @samp{[1, 3, 5]} onto the stack. To enter a matrix, build each row
- on the stack as a vector, then use a final @key{PACK} to collect the
- rows into a matrix.
- X
- @key{UNPK} unpacks the vector on the stack, pushing each of its
- components separately.
- X
- @key{INDX} removes an integer @var{n}, then builds a vector of
- integers from 1 to @var{n}. @kbd{INV INDX} takes three numbers
- from the stack: The vector size @var{n}, the starting number,
- and the increment. @kbd{BLD} takes an integer @var{n} and any
- value @var{x} and builds a vector of @var{n} copies of @var{x}.
- X
- @key{IDNT} removes an integer @var{n}, then builds an @var{n}-by-@var{n}
- identity matrix.
- X
- @key{LEN} replaces a vector by its length, an integer.
- X
- @key{...} turns on or off ``abbreviated'' display mode for large vectors.
- X
- @key{MINV}, @key{MDET}, @key{MTRN}, and @key{CROSS} are the matrix
- inverse, determinant, and transpose, and vector cross product.
- X
- @key{SUM} replaces a vector by the sum of its elements. It is
- equivalent to @kbd{u +} in normal Calc (@pxref{Statistical Operations}).
- @key{PROD} computes the product of the elements of a vector, and
- @key{MAX} computes the maximum of all the elements of a vector.
- X
- @key{INV SUM} computes the alternating sum of the first element
- minus the second, plus the third, minus the fourth, and so on.
- @key{INV MAX} computes the minimum of the vector elements.
- X
- @key{HYP SUM} computes the mean of the vector elements.
- @key{HYP PROD} computes the sample standard deviation.
- X
- @key{MAP*} multiplies two vectors elementwise. It is equivalent
- to the @kbd{V M *} command (in map-by-elements mode; @pxref{Reducing
- and Mapping}). @key{MAP^} computes powers elementwise. The arguments
- must be vectors of equal length, or one must be a vector and the
- other must be a plain number. For example, @kbd{2 MAP^} squares all
- the elements of a vector.
- X
- @key{MAP$} maps the formula on the top of the stack across the
- vector in the second-to-top position. If the formula contains
- several variables, Calc takes that many vectors starting at the
- second-to-top position and matches them to the variables in
- alphabetical order. The result is a vector of the same size as
- the input vectors, whose elements are the formula evaluated with
- the variables set to the various sets of numbers in those vectors.
- For example, you could simulate @key{MAP^} using @key{MAP$} with
- the formula @cite{x^y}.
- X
- The @kbd{"x"} key pushes the variable name @cite{x} onto the
- stack. To build the formula @cite{x^2 + 6}, you would use the
- key sequence @kbd{"x" 2 y^x 6 +}. This formula would then be
- suitable for use with the @key{MAP$} key described above.
- With @key{INV}, @key{HYP}, or @key{INV} and @key{HYP}, the
- @kbd{"x"} key pushes the variable names @cite{y}, @cite{z}, and
- @cite{t}, respectively.
- X
- @node Keypad Modes Menu, , Keypad Vectors Menu, Keypad Mode
- @section Modes Menu
- X
- @group
- @smallexample
- |----+----+----+----+----+----5
- |FLT |FIX |SCI |ENG |GRP | |
- |----+----+----+----+----+----|
- |RAD |DEG |FRAC|POLR|SYMB|PREC|
- |----+----+----+----+----+----|
- |SWAP|RLL3|RLL4|OVER|STO |RCL |
- |----+----+----+----+----+----|
- @end smallexample
- @end group
- X
- @noindent
- The keys in this menu manipulate modes, variables, and the stack.
- X
- The @key{FLT}, @key{FIX}, @key{SCI}, and @key{ENG} keys select
- floating-point, fixed-point, scientific, or engineering notation.
- @key{FIX} prompts for the number of digits to display. You can
- respond using the keyboard or the keypad digit and @key{ENTER} keys.
- The other three modes always display full precision. You can
- type a numeric prefix using the keyboard, then click on one of
- these keys, to set a different display precision.
- X
- The @key{GRP} key turns grouping of digits with commas on or off.
- @kbd{INV GRP} enables grouping to the right of the decimal point as
- well as to the left.
- X
- The @key{RAD} and @key{DEG} keys switch between radians and degrees
- for trigonometric functions.
- X
- The @key{FRAC} key turns Fraction mode on or off. This affects
- whether commands like @kbd{/} with integer arguments produce
- fractional or floating-point results.
- X
- The @key{POLR} key turns Polar mode on or off, determining whether
- polar or rectangular complex numbers are used by default.
- X
- The @key{SYMB} key turns Symbolic mode on or off, in which
- operations that would produce inexact floating-point results
- are left unevaluated as algebraic formulas.
- X
- The @key{PREC} key selects the current precision. Answer with
- the keyboard or with the keypad digit and @key{ENTER} keys.
- X
- The @key{SWAP} key exchanges the top two stack elements.
- The @key{RLL3} key rotates the top three stack elements upwards.
- The @key{RLL4} key rotates the top four stack elements upwards.
- The @key{OVER} key duplicates the second-to-top stack element.
- X
- The @key{STO} and @key{RCL} keys are analogous to @kbd{s t} and
- @kbd{s r} in regular Calc. @xref{Store and Recall}. Click the
- @key{STO} or @key{RCL} key, then one of the ten digits. (Named
- variables are not available in Keypad Mode.) You can also use,
- for example, @kbd{STO + 3} to add to register 3.
- X
- @node Embedded Mode, Programming, Keypad Mode, Top
- @chapter Embedded Mode
- X
- @noindent
- Embedded Mode in Calc provides an alternative to copying numbers
- and formulas back and forth between editing buffers and the Calc
- stack. In Embedded Mode, your editing buffer becomes temporarily
- linked to the stack and this copying is taken care of automatically.
- X
- @menu
- * Basic Embedded Mode::
- * More About Embedded Mode::
- * Assignments in Embedded Mode::
- * Mode Settings in Embedded Mode::
- * Customizing Embedded Mode::
- @end menu
- X
- @node Basic Embedded Mode, More About Embedded Mode, Embedded Mode, Embedded Mode
- @section Basic Embedded Mode
- X
- @noindent
- @kindex M-# e
- @pindex calc-embedded
- To enter Embedded mode, position the Emacs point (cursor) on a
- formula in any buffer and press @kbd{M-# e} (@code{calc-embedded}).
- Note that @kbd{M-# e} is not to be used in the Calc stack buffer
- like most Calc commands, but rather in regular editing buffers that
- are visiting your own files.
- X
- Calc normally scans backward and forward in the buffer for the
- nearest opening and closing @dfn{formula delimiters}. The simplest
- delimiters are blank lines. Other delimiters that Embedded Mode
- understands are:
- X
- @enumerate
- @item
- The @TeX{} math delimiters @samp{$ $} @samp{$$ $$}, @samp{\[ \]}, and @samp{\( \)};
- @item
- Lines beginning with @samp{\begin} and @samp{\end};
- @item
- Lines beginning with @samp{@@} (Texinfo delimiters).
- @item
- Lines beginning with @samp{.EQ} and @samp{.EN} (@dfn{eqn} delimiters);
- @item
- Lines containing a single @samp{%} or @samp{.\"} symbol and nothing else.
- @end enumerate
- X
- @xref{Customizing Embedded Mode}, to see how to make Calc recognize
- your own favorite delimiters. Delimiters like @samp{$ $} can appear
- on their own lines or in-line with the formula.
- X
- If you give a positive or negative numeric prefix argument, Calc
- instead uses the current point as one end of the formula, and moves
- forward or backward (respectively) by that many lines to find the
- other end. Explicit delimiters are not necessary in this case.
- X
- With a prefix argument of zero, Calc uses the current region
- (delimited by point and mark) instead of formula delimiters.
- X
- @kindex M-# w
- @pindex calc-embedded-word
- With a prefix argument of @kbd{C-u} only, Calc scans for the first
- non-numeric character (i.e., the first character that is not a
- digit, sign, decimal point, or upper- or lower-case @samp{e})
- forward and backward to delimit the formula. @kbd{M-# w}
- (@code{calc-embedded-word}) is equivalent to @kbd{C-u M-# e}.
- X
- When you enable Embedded mode for a formula, Calc reads the text
- between the delimiters and tries to interpret it as a Calc formula.
- It's best if the current Calc language mode is correct for the
- formula, but Calc can generally identify @TeX{} formulas and
- Big-style formulas even if the language mode is wrong. If Calc
- can't make sense of the formula, it beeps and refuses to enter
- Embedded mode. But if the current language is wrong, Calc can
- sometimes parse the formula successfully (but incorrectly);
- for example, the C expression @samp{atan(a[1])} can be parsed
- in Normal language mode, but the @code{atan} won't correspond to
- the built-in @code{arctan} function, and the @samp{a[1]} will be
- interpreted as @samp{a} times the vector @samp{[1]}!
- X
- If you press @kbd{M-# e} or @kbd{M-# w} to activate an embedded
- formula which is blank, say with the cursor on the space between
- the two delimiters @samp{$ $}, Calc will immediately prompt for
- an algebraic entry.
- X
- Only one formula in one buffer can be enabled at a time. If you
- move to another area of the current buffer and give Calc commands,
- Calc turns Embedded mode off for the old formula and then tries
- to restart Embedded mode at the new position. Other buffers are
- not affected by Embedded mode.
- X
- When Embedded mode begins, Calc pushes the current formula onto
- the stack. No Calc stack window is created; however, Calc copies
- the top-of-stack position into the original buffer at all times.
- You can create a Calc window by hand with @kbd{M-# o} if you
- find you need to see the entire stack.
- X
- For example, typing @kbd{M-# e} while somewhere in the formula
- @samp{n>2} in the following line enables Embedded mode on that
- inequality:
- X
- @example
- We define $F_n = F_(n-1)+F_(n-2)$ for all $n>2$.
- @end example
- X
- The formula @cite{n>2} will be pushed onto the Calc stack, and
- the top of stack will be copied back into the editing buffer.
- This means that spaces will appear around the @samp{>} symbol
- to match Calc's usual display style:
- X
- @example
- We define $F_n = F_(n-1)+F_(n-2)$ for all $n > 2$.
- @end example
- X
- No spaces have appeared around the @samp{+} sign because it's
- in a different formula, one which we have not yet touched with
- Embedded mode.
- X
- Now that Embedded mode is enabled, keys you type in this buffer
- are interpreted as Calc commands. At this point we might use
- the ``commute'' command @kbd{j C} to reverse the inequality.
- This is a selection-based command for which we first need to
- move the cursor onto the operator (@samp{>} in this case) that
- needs to be commuted.
- X
- @example
- We define $F_n = F_(n-1)+F_(n-2)$ for all $2 < n$.
- @end example
- X
- The @kbd{M-# o} command is a useful way to open a Calc window
- without actually selecting that window. Giving this command
- verifies that @samp{2 < n} is also on the Calc stack. Typing
- @kbd{17 RET} would produce:
- X
- @example
- We define $F_n = F_(n-1)+F_(n-2)$ for all $17$.
- @end example
- X
- @noindent
- with @samp{2 < n} and @samp{17} on the stack; typing @key{TAB}
- at this point will exchange the two stack values and restore
- @samp{2 < n} to the embedded formula. Even though you can't
- normally see the stack in Embedded mode, it is still there and
- it still operates in the same way. But, as with old-fashioned
- RPN calculators, you can only see the value at the top of the
- stack at any given time (unless you use @kbd{M-# o}).
- X
- Typing @kbd{M-# e} again turns Embedded mode off. The Calc
- window reveals that the formula @samp{2 < n} is automatically
- removed from the stack, but the @samp{17} is not. Entering
- Embedded mode always pushes one thing onto the stack, and
- leaving Embedded mode always removes one thing. Anything else
- that happens on the stack is entirely your business as far as
- Embedded mode is concerned.
- X
- If you press @kbd{M-# e} in the wrong place by accident, it is
- possible that Calc will be able to parse the nearby text as a
- formula and will mangle that text in an attempt to redisplay it
- ``properly'' in the current language mode. If this happens,
- press @kbd{M-# e} again to exit Embedded mode, then give the
- regular Emacs ``undo'' command (@kbd{C-_} or @kbd{C-x u}) to put
- the text back the way it was before Calc edited it. Note that Calc's
- own Undo command (typed before you turn Embedded mode back off)
- will not do you any good, because as far as Calc is concerned
- you haven't done anything with this formula yet.
- X
- @node More About Embedded Mode, Assignments in Embedded Mode, Basic Embedded Mode, Embedded Mode
- @section More About Embedded Mode
- X
- @noindent
- When Embedded mode ``activates'' a formula, i.e., when it examines
- the formula for the first time since the buffer was created or
- loaded, Calc tries to sense the language in which the formula was
- written. If the formula contains any @TeX{}-like @samp{\} sequences,
- it is parsed (i.e., read) in @TeX{} mode. If the formula appears to
- be written in multi-line Big mode, it is parsed in Big mode. Otherwise,
- it is parsed according to the current language mode.
- X
- Note that Calc does not change the current language mode according
- to what it finds. Even though it can read a @TeX{} formula when
- not in @TeX{} mode, it will immediately rewrite this formula using
- whatever language mode is in effect. You must then type @kbd{d T}
- to switch Calc permanently into @TeX{} mode if that is what you
- desire.
- X
- @tex
- \bigskip
- @end tex
- X
- @kindex d p
- @pindex calc-show-plain
- Calc's parser is unable to read certain kinds of formulas. For
- example, with @kbd{v ]} (@code{calc-matrix-brackets}) you can
- specify matrix display styles which the parser is unable to
- recognize as matrices. The @kbd{d p} (@code{calc-show-plain})
- command turns on a mode in which a ``plain'' version of a
- formula is placed in front of the fully-formatted version.
- When Calc reads a formula that has such a plain version in
- front, it reads the plain version and ignores the formatted
- version.
- X
- Plain formulas are preceded and followed by @samp{%%%} signs
- by default. This notation has the advantage that the @samp{%}
- character begins a comment in @TeX{}, so if your formula is
- embedded in a @TeX{} document its plain version will be
- invisible in the final printed copy. @xref{Customizing
- Embedded Mode}, to see how to change the ``plain'' formula
- delimiters, say to something that @dfn{eqn} or some other
- formatter will treat as a comment.
- X
- There are several notations which Calc's parser for ``big''
- formatted formulas can't yet recognize. In particular, it can't
- read the large symbols for @code{sum}, @code{prod}, and @code{integ},
- and it can't handle @samp{=>} with the righthand argument omitted.
- Also, Calc won't recognize special formats you have defined with
- the @kbd{Z C} command (@pxref{User-Defined Compositions}). In
- these cases it is important to use ``plain'' mode to make sure
- Calc will be able to read your formula later.
- X
- Another example where ``plain'' mode is important is if you have
- specified a float mode with few digits of precision. Normally
- any digits that are computed but not displayed will simply be
- lost when you save and re-load your embedded buffer, but ``plain''
- mode allows you to make sure that the complete number is present
- in the file as well as the rounded-down number.
- X
- @tex
- \bigskip
- @end tex
- X
- Embedded buffers remember active formulas for as long as they
- exist in Emacs memory. Suppose you have an embedded formula
- which is @c{$\pi$}
- @cite{pi} to the normal 12 decimal places, and then
- type @kbd{C-u 5 d n} to display only five decimal places.
- If you then type @kbd{d n}, all 12 places reappear because the
- full number is still there on the Calc stack. More surprisingly,
- even if you exit Embedded mode and later re-enter it for that
- formula, typing @kbd{d n} will restore all 12 places because
- each buffer remembers all its active formulas. However, if you
- save the buffer in a file and reload it in a new Emacs session,
- all non-displayed digits will have been lost unless you used
- ``plain'' mode.
- X
- @tex
- \bigskip
- @end tex
- X
- In some applications of Embedded mode, you will want to have a
- sequence of copies of a formula that show its evolution as you
- work on it. For example, you might want to have a sequence
- like this in your file (elaborating here on the example from
- the ``Getting Started'' chapter):
- X
- @smallexample
- The derivative of
- X
- X ln(ln(x))
- X
- is
- X
- X @r{(the derivative of }ln(ln(x))@r{)}
- X
- whose value at x = 2 is
- X
- X @r{(the value)}
- X
- and at x = 3 is
- X
- X @r{(the value)}
- @end smallexample
- X
- @kindex M-# d
- @pindex calc-embedded-duplicate
- The @kbd{M-# d} (@code{calc-embedded-duplicate}) command is a
- handy way to make sequences like this. If you type @kbd{M-# d},
- the formula under the cursor (which may or may not have Embedded
- mode enabled for it at the time) is copied immediately below and
- Embedded mode is then enabled for that copy.
- X
- For this example, you would start with just
- X
- @smallexample
- The derivative of
- X
- X ln(ln(x))
- @end smallexample
- X
- @noindent
- and press @kbd{M-# d} with the cursor on this formula. The result
- is
- X
- @smallexample
- The derivative of
- X
- X ln(ln(x))
- X
- X
- X ln(ln(x))
- @end smallexample
- X
- @noindent
- with the second copy of the formula enabled in Embedded mode.
- You can now press @kbd{a d x RET} to take the derivative, and
- @kbd{M-# d M-# d} to make two more copies of the derivative.
- To complete the computations, type @kbd{3 s l x RET} to evaluate
- the last formula, then move up to the second-to-last formula
- and type @kbd{2 s l x RET}.
- X
- Finally, you would want to press @kbd{M-# e} to exit Embedded
- mode, then go up and insert the necessary text in between the
- various formulas and numbers.
- X
- @tex
- \bigskip
- @end tex
- X
- @kindex M-# f
- @kindex M-# '
- @pindex calc-embedded-new-formula
- The @kbd{M-# f} (@code{calc-embedded-new-formula}) command
- creates a new embedded formula at the current point. It inserts
- some default delimiters, which are usually just blank lines,
- and then does an algebraic entry to get the formula (which is
- then enabled for Embedded mode). This is just shorthand for
- typing the delimiters yourself, positioning the cursor between
- the new delimiters, and pressing @kbd{M-# e}. The key sequence
- @kbd{M-# '} is equivalent to @kbd{M-# f}.
- X
- @kindex M-# n
- @kindex M-# p
- @pindex calc-embedded-next
- @pindex calc-embedded-previous
- The @kbd{M-# n} (@code{calc-embedded-next}) and @kbd{M-# p}
- (@code{calc-embedded-previous}) commands move the cursor to the
- next or previous active embedded formula in the buffer. They
- can take positive or negative prefix arguments to move by several
- formulas. Note that these commands do not actually examine the
- text of the buffer looking for formulas; they only see formulas
- which have previously been activated in Embedded mode. In fact,
- @kbd{M-# n} and @kbd{M-# p} are a useful way to tell which
- embedded formulas are currently active. Also, note that these
- commands do not enable Embedded mode on the next or previous
- formula, they just move the cursor. (By the way, @kbd{M-# n} is
- not as awkward to type as it may seem, because @kbd{M-#} ignores
- Shift and Meta on the second keystroke: @kbd{M-# M-N} can be typed
- by holding down Shift and Meta and alternately typing two keys.)
- X
- @kindex M-# `
- @pindex calc-embedded-edit
- The @kbd{M-# `} (@code{calc-embedded-edit}) command edits the
- embedded formula at the current point as if by @kbd{`} (@code{calc-edit}).
- Embedded mode does not have to be enabled for this to work. Press
- @kbd{M-# M-#} to finish the edit, or @kbd{M-# x} to cancel.
- X
- @node Assignments in Embedded Mode, Mode Settings in Embedded Mode, More About Embedded Mode, Embedded Mode
- @section Assignments in Embedded Mode
- X
- @noindent
- The @samp{:=} (assignment) and @samp{=>} (``evaluates-to'') operators
- are especially useful in Embedded mode. They allow you to make
- a definition in one formula, then refer to that definition in
- other formulas embedded in the same buffer.
- X
- An embedded formula which is an assignment to a variable, as in
- X
- @example
- foo := 5
- @end example
- X
- @noindent
- records @cite{5} as the stored value of @code{foo} for the
- purposes of Embedded mode operations in the current buffer. It
- does @emph{not} actually store @cite{5} as the ``global'' value
- of @code{foo}, however. Regular Calc operations, and Embedded
- formulas in other buffers, will not see this assignment.
- X
- One way to use this assigned value is simply to create an
- Embedded formula elsewhere that refers to @code{foo}, and to press
- @kbd{=} in that formula. However, this permanently replaces the
- @code{foo} in the formula with its current value. More interesting
- is to use @samp{=>} elsewhere:
- X
- @example
- foo + 7 => 12
- @end example
- X
- @xref{Evaluates-To Operator}, for a general discussion of @samp{=>}.
- X
- If you move back and change the assignment to @code{foo}, any
- @samp{=>} formulas which refer to it are automatically updated.
- X
- @example
- foo := 17
- X
- foo + 7 => 24
- @end example
- X
- The obvious question then is, @emph{how} can one easily change the
- assignment to @code{foo}? If you simply select the formula in
- Embedded mode and type 17, the assignment itself will be replaced
- by the 17. The effect on the other formula will be that the
- variable @code{foo} becomes unassigned:
- X
- @example
- 17
- X
- foo + 7 => foo + 7
- @end example
- X
- The right thing to do is first to use a selection command (@kbd{j 2}
- will do the trick) to select the righthand side of the assignment.
- Then, @kbd{17 TAB DEL} will swap the 17 into place (@pxref{Selecting
- Subformulas}, to see how this works).
- X
- @kindex M-# j
- @pindex calc-embedded-select
- The @kbd{M-# j} (@code{calc-embedded-select}) command provides an
- easy way to operate on assigments. It is just like @kbd{M-# e},
- except that if the enabled formula is an assignment, it uses
- @kbd{j 2} to select the righthand side. If the enabled formula
- is an evaluates-to, it uses @kbd{j 1} to select the lefthand side.
- A formula can also be a combination of both:
- X
- @example
- bar := foo + 3 => 20
- @end example
- X
- @noindent
- in which case @kbd{M-# j} will select the middle part (@samp{foo + 3}).
- X
- The formula is automatically deselected when you leave Embedded
- mode.
- X
- @kindex M-# u
- @kindex M-# =
- @pindex calc-embedded-update
- Another way to change the assignment to @code{foo} would simply be
- to edit the number using regular Emacs editing rather then Embedded
- mode. Then, we have to find a way to get Embedded mode to notice
- the change. The @kbd{M-# u} or @kbd{M-# =}
- (@code{calc-embedded-update-formula}) command is a convenient way
- to do this.@refill
- X
- @example
- foo := 6
- X
- foo + 7 => 13
- @end example
- X
- Pressing @kbd{M-# u} is much like pressing @kbd{M-# e = M-# e}, that
- is, temporarily enabling Embedded mode for the formula under the
- cursor and then evaluating it with @kbd{=}. But @kbd{M-# u} does
- not actually use @kbd{M-# e}, and in fact another formula somewhere
- else can be enabled in Embedded mode while you use @kbd{M-# u} and
- that formula will not be disturbed.
- X
- With a numeric prefix argument, @kbd{M-# u} updates all active
- @samp{=>} formulas in the buffer. Formulas which have not yet
- been activated in Embedded mode, and formulas which do not have
- @samp{=>} as their top-level operator, are not affected by this.
- X
- With a plain @kbd{C-u} prefix, @kbd{C-u M-# u} updates only in the
- region between mark and point rather than in the whole buffer.
- X
- @kbd{M-# u} is also a handy way to activate a formula, such as an
- @samp{=>} formula that has freshly been typed in or loaded from a
- file.
- X
- @kindex M-# a
- @pindex calc-embedded-activate
- The @kbd{M-# a} (@code{calc-embedded-activate}) command scans
- through the current buffer and activates all embedded formulas
- that contain @samp{:=} or @samp{=>} symbols. This does not mean
- that Embedded mode is actually turned on, but only that the
- formulas' positions are registered with Embedded mode so that
- the @samp{=>} values can be properly updated as assignments are
- changed.
- X
- It is a good idea to type @kbd{M-# a} right after loading a file
- that uses embedded @samp{=>} operators. Emacs includes a nifty
- ``buffer-local variables'' feature that you can use to do this
- automatically. The idea is to place near the end of your file
- a few lines that look like this:
- X
- @example
- --- Local Variables: ---
- --- eval:(calc-embedded-activate) ---
- --- End: ---
- @end example
- X
- @noindent
- where the leading and trailing @samp{---} can be replaced by
- any suitable strings (which must be the same on all three lines)
- or omitted altogether; in a @TeX{} file, @samp{%} would be a good
- leading string and no trailing string would be necessary. In a
- C program, @samp{/*} and @samp{*/} would be good leading and
- trailing strings.
- X
- When Emacs loads a file into memory, it checks for a Local Variables
- section like this one at the end of the file. If it finds this
- section, it does the specified things (in this case, running
- @kbd{M-# a} automatically) before editing of the file begins.
- The Local Variables section must be within 3000 characters of the
- end of the file for Emacs to find it, and it must be in the last
- page of the file if the file has any page separators.
- @xref{File Variables, , Local Variables in Files, emacs, the
- Emacs manual}.
- X
- Note that @kbd{M-# a} does not update the formulas it finds.
- To do this, type, say, @kbd{M-1 M-# u} after @kbd{M-# a}.
- Generally this should not be a problem, though, because the
- formulas will have been up-to-date already when the file was
- saved.
- X
- Normally, @kbd{M-# a} activates all the formulas it finds, but
- any previous active formulas remain active as well. With a
- positive numeric prefix argument, @kbd{M-# a} first deactivates
- all current active formulas, then actives the ones it finds in
- its scan of the buffer. With a negative prefix argument,
- @kbd{M-# a} simply deactivates all formulas.
- X
- Embedded mode has two symbols, @samp{Active} and @samp{~Active},
- which it puts next to the major mode name in a buffer's mode line.
- It puts @samp{Active} if it has reason to believe that all
- formulas in the buffer are active, because you have typed @kbd{M-# a}
- and Calc has not since had to deactivate any formulas (which can
- happen if Calc goes to update an @samp{=>} formula somewhere because
- a variable changed, and finds that the formula is no longer there
- due to some kind of editing outside of Embedded mode). Calc puts
- @samp{~Active} in the mode line if some, but probably not all,
- formulas in the buffer are active. This happens if you activate
- a few formulas one at a time but never use @kbd{M-# a}, or if you
- used @kbd{M-# a} but then Calc had to deactivate a formula
- because it lost track of it. If neither of these symbols appears
- in the mode line, no embedded formulas are active in the buffer
- (e.g., before Embedded mode has been used, or after a @kbd{M-- M-# a}).
- X
- Embedded formulas can refer to assignments both before and after them
- in the buffer. If there are several assignments to a variable, the
- nearest preceding assignment is used if there is one, otherwise the
- following assignment is used.
- X
- @example
- x => 1
- X
- x := 1
- X
- x => 1
- X
- x := 2
- X
- x => 2
- @end example
- X
- As well as simple variables, you can also assign to subscript
- expressions of the form @samp{@var{var}_@var{number}} (as in
- @code{x_0}), or @samp{@var{var}_@var{var}} (as in @code{x_max}).
- Assignments to other kinds of objects can be represented by Calc,
- but the automatic linkage between assignments and references works
- only for plain variables and these two kinds of subscript expressions.
- X
- If there are no assignments to a given variable, the global
- stored value for the variable is used (@pxref{Storing Variables}),
- or, if no value is stored, the variable is left in symbolic form.
- Note that global stored values will be lost when the file is saved
- and loaded in a later Emacs session, unless you have used the
- @kbd{s p} (@code{calc-permanent-variable}) command to save them;
- @pxref{Operations on Variables}.
- X
- The @kbd{m C} (@code{calc-auto-recompute}) command turns automatic
- recomputation of @samp{=>} forms on and off. If you turn automatic
- recomputation off, you will have to use @kbd{M-# u} to update these
- formulas manually after an assignment has been changed. If you
- plan to change several assignments at once, it may be more efficient
- to type @kbd{m C}, change all the assignments, then use @kbd{M-1 M-# u}
- to update the entire buffer afterwards. The @kbd{m C} command also
- controls @samp{=>} formulas on the stack; @pxref{Evaluates-To
- Operator}. When you turn automatic recomputation back on, the
- stack will be updated but the Embedded buffer will not; you must
- use @kbd{M-# u} to update the buffer by hand.
- X
- @node Mode Settings in Embedded Mode, Customizing Embedded Mode, Assignments in Embedded Mode, Embedded Mode
- @section Mode Settings in Embedded Mode
- X
- @noindent
- Embedded Mode has a rather complicated mechanism for handling mode
- settings in Embedded formulas. It is possible to put annotations
- in the file that specify mode settings either global to the entire
- file or local to a particular formula or formulas. In the latter
- case, different modes can be specified for use when a formula
- is the enabled Embedded Mode formula.
- X
- When you give any mode-setting command, like @kbd{m f} (for fraction
- mode) or @kbd{d s} (for scientific notation), Embedded Mode adds
- a line like the following one to the file just before the opening
- delimiter of the formula.
- X
- @example
- % [calc-mode: fractions: t]
- % [calc-mode: float-format: (sci 0)]
- @end example
- X
- When Calc interprets an embedded formula, it scans the text before
- the formula for mode-setting annotations like these and sets the
- Calc buffer to match these modes. Modes not explicitly described
- in the file are not changed. Calc scans all the way to the top of
- the file, or until a line of the form
- X
- @example
- % [calc-defaults]
- @end example
- X
- @noindent
- which you can insert at strategic places in the file if this backward
- scan is getting too slow, or just to provide a barrier between one
- ``zone'' of mode settings and another.
- X
- If the file contains several annotations for the same mode, the
- closest one before the formula is used. Annotations after the
- formula are never used (except for global annotations, described
- below).
- X
- The scan does not look for the leading @samp{% }, only for the
- square brackets and the text they enclose. You can edit the mode
- annotations to a style that works better in context if you wish.
- @xref{Customizing Embedded Mode}, to see how to change the style
- that Calc uses when it generates the annotations. You can write
- mode annotations into the file yourself if you know the syntax;
- the easiest way to find the syntax for a given mode is to let
- Calc write the annotation for it once and see what it does.
- X
- If you give a mode-changing command for a mode that already has
- a suitable annotation just above the current formula, Calc will
- modify that annotation rather than generating a new, conflicting
- one.
- X
- Mode annotations have three parts, separated by colons. (Spaces
- after the colons are optional.) The first identifies the kind
- of mode setting, the second is a name for the mode itself, and
- the third is the value in the form of a Lisp symbol, number,
- or list. Annotations with unrecognizable text in the first or
- second parts are ignored. The third part is not checked to make
- sure the value is of a legal type or range; if you write an
- annotation by hand, be sure to give a proper value or results
- will be unpredictable. Mode setting annotations are case-sensitive.
- X
- While Embedded Mode is enabled, the word @code{Local} appears in
- the mode line. This is to show that mode setting commands generate
- annotations that are ``local'' to the current formula or set of
- formulas. The @kbd{m R} (@code{calc-mode-record-mode}) command
- causes Calc to generate different kinds of annotations. Pressing
- @kbd{m R} repeatedly cycles through the possible modes.
- X
- @code{LocEdit} and @code{LocPerm} modes generate annotations
- that look like this, respectively:
- X
- @example
- % [calc-edit-mode: fractions t]
- % [calc-perm-mode: fractions nil]
- @end example
- X
- The first kind of annotation will be used only while a formula
- is enabled in Embedded Mode. The second kind will be used only
- when the formula is @emph{not} enabled. (Whether the formula
- is ``active'' or not, i.e., whether Calc has seen this formula
- yet, is not relevant here.)
- X
- @code{Global} mode generates an annotation like this at the end
- of the file:
- X
- @example
- % [calc-global-mode: fractions t]
- @end example
- X
- Global mode annotations affect all formulas throughout the file,
- and may appear anywhere in the file. This allows you to tuck your
- mode annotations somewhere out of the way, say, on a new page of
- the file, as long as those mode settings are suitable for all
- formulas in the file.
- X
- Enabling a formula with @kbd{M-# e} causes a fresh scan for local
- mode annotations; you will have to use this after adding annotations
- above a formula by hand to get the formula to notice them. Updating
- a formula with @kbd{M-# u} will also re-scan the local modes, but
- global modes are only re-scanned by @kbd{M-# a}
- (@code{calc-embedded-activate}).
- X
- Another way that modes can get out of date is if you add a local
- mode annotation to a formula that has another formula after it.
- In this example, we have used the @kbd{d s} command while the
- first of the two embedded formulas is active. But the second
- formula has not changed its style to match, even though by the
- rules of reading annotations the @samp{(sci 0)} applies to it, too.
- X
- @example
- % [calc-mode: float-format: (sci 0)]
- 1.23e2
- X
- 456.
- @end example
- X
- We would have to go down to the other formula and press @kbd{M-# u}
- on it in order to get it to notice the new annotation.
- X
- Two more mode-recording mode selectable by @kbd{m R} are @code{Save}
- (which works even outside of Embedded Mode), in which mode settings
- are recorded permanently in your Emacs startup file @file{~/.emacs}
- rather than by annotating the current document, and no-recording
- mode (where there is no symbol like @code{Save} or @code{Local} in
- the mode line), in which mode-changing commands do not leave any
- annotations at all.
- X
- When Embedded Mode is not enabled, mode-recording modes except
- for @code{Save} have no effect.
- X
- @node Customizing Embedded Mode, , Mode Settings in Embedded Mode, Embedded Mode
- @section Customizing Embedded Mode
- X
- @noindent
- You can modify Embedded Mode's behavior by setting various Lisp
- variables described here. Use @kbd{M-x set-variable} or
- @kbd{M-x edit-options} to adjust a variable on the fly, or
- put a suitable @code{setq} statement in your @file{~/.emacs}
- file to set a variable permanently. (Another possibility would
- be to use a file-local variable annotation at the end of the
- file; @xref{File Variables, , Local Variables in Files, emacs, the
- Emacs manual}.)
- X
- While none of these variables will be buffer-local by default, you
- can make any of them local to any embedded-mode buffer. (Their
- values in the @samp{*Calculator*} buffer are never used.)
- X
- @vindex calc-embedded-open-formula
- The @code{calc-embedded-open-formula} variable holds a regular
- expression for the opening delimiter of a formula. @xref{Regexp Search,
- , Regular Expression Search, emacs, the Emacs manual}, to see
- how regular expressions work. Basically, a regular expression is a
- pattern that Calc can search for. A regular expression that considers
- blank lines, @samp{$}, and @samp{$$} to be opening delimiters is
- @code{"\\`\\|^\n\\|\\$\\$?"}. Just in case the meaning of this
- regular expression is not completely plain, let's go through it
- in detail.
- X
- The surrounding @samp{" "} marks quote the text between them as a
- Lisp string. If you left them off, @code{set-variable} or
- @code{edit-options} would try to read the regular expression as a
- Lisp program.
- X
- The most obvious property of this regular expression is that it
- contains indecently many backslashes. There are actually two levels
- of backslash usage going on here. First, when Lisp reads a quoted
- string, all pairs of characters beginning with a backslash are
- interpreted as special characters. Here, @code{\n} changes to a
- new-line character, and @code{\\} changes to a single backslash.
- So the actual regular expression seen by Calc is
- @samp{\`\|^ @r{(newline)} \|\$\$?}.
- X
- Regular expressions also consider pairs beginning with backslash
- to have special meanings. Sometimes the backslash is used to quote
- a character that otherwise would have a special meaning in a regular
- expression, like @samp{$}, which normally means ``end-of-line,''
- or @samp{?}, which means that the preceding item is optional. So
- @samp{\$\$?} matches either one or two dollar signs.
- X
- The other codes in this regular expression are @samp{^}, which matches
- ``beginning-of-line,'' @samp{\|}, which means ``or,'' and @samp{\`},
- which matches ``beginning-of-buffer.'' So the whole pattern means
- that a formula begins at the beginning of the buffer, or on a newline
- that occurs at the beginning of a line (i.e., a blank line), or at
- one or two dollar signs.
- X
- The default value of @code{calc-embedded-open-formula} looks just
- like this example, with several more alternatives added on to
- recognize various other common kinds of delimiters.
- X
- By the way, the reason to use @samp{^\n} rather than @samp{^$}
- or @samp{\n\n}, which also would appear to match blank lines,
- is that the former expression actually ``consumes'' only one
- newline character as @emph{part of} the delimiter, whereas the
- latter expressions consume zero or two newlines, respectively.
- The former choice gives the most natural behavior when Calc
- must operate on a whole formula including its delimiters.
- X
- See the Emacs manual for complete details on regular expressions.
- But just for your convenience, here is a list of all characters
- which must be quoted with backslash (like @samp{\$}) to avoid
- some special interpretation: @samp{. * + ? [ ] ^ $ \}. (Note
- the backslash in this list; for example, to match @samp{\[} you
- must use @samp{"\\\\\\["}. An exercise for the reader is to
- account for each of these six backslashes!)
- X
- @vindex calc-embedded-close-formula
- The @code{calc-embedded-close-formula} variable holds a regular
- expression for the closing delimiter of a formula. A closing
- regular expression to match the above example would be
- @samp{"\\'\\|\n$\\|\\$\\$?"}. This is almost the same as the
- other one, except it now uses @samp{\'} (``end-of-buffer'') and
- @samp{\n$} (newline occurring at end of line, yet another way
- of describing a blank line that is more appropriate for this
- case).
- X
- @vindex calc-embedded-open-word
- @vindex calc-embedded-close-word
- The @code{calc-embedded-open-word} and @code{calc-embedded-close-word}
- variables are similar expressions used when you type @kbd{M-# w}
- instead of @kbd{M-# e} to enable Embedded mode.
- X
- @vindex calc-embedded-open-plain
- The @code{calc-embedded-open-plain} variable is a string which
- begins a ``plain'' formula written in front of the formatted
- formula when @kbd{d p} mode is turned on. Note that this is an
- actual string, not a regular expression, because Calc must be able
- to write this string into a buffer as well as to recognize it.
- The default string is @samp{"%%% "} (note the trailing space).
- X
- @vindex calc-embedded-close-plain
- The @code{calc-embedded-close-plain} variable is a string which
- ends a ``plain'' formula. The default is @samp{" %%%\n"}. Without
- the trailing newline here, the first line of a ``big'' mode formula
- that followed might be shifted over with respect to the other lines.
- X
- @vindex calc-embedded-open-new-formula
- The @code{calc-embedded-open-new-formula} variable is a string
- which is inserted at the front of a new formula when you type
- @kbd{M-# f}. Its default value is @samp{"\n\n"}. If this
- string begins with a newline character and the @kbd{M-# f} is
- typed at the beginning of a line, @kbd{M-# f} will skip this
- first newline to avoid introducing unnecessary blank lines in
- the file.
- X
- @vindex calc-embedded-close-new-formula
- The @code{calc-embedded-close-new-formula} variable is the corresponding
- string which is inserted at the end of a new formula. Its default
- value is also @samp{"\n\n"}. The final newline is omitted by
- @kbd{M-# f} if typed at the end of a line. (It follows that if
- @kbd{M-# f} is typed on a blank line, both a leading opening
- newline and a trailing closing newline are omitted.)
- X
- @vindex calc-embedded-announce-formula
- The @code{calc-embedded-announce-formula} variable is a regular
- expression which is sure to be followed by an embedded formula.
- The @kbd{M-# a} command searches for this pattern as well as for
- @samp{=>} and @samp{:=} operators. Note that @kbd{M-# a} will
- not activate just anything surrounded by formula delimiters; after
- all, blank lines are considered formula delimiters by default!
- But if your language includes a delimiter which can only occur
- actually in front of a formula, you can take advantage of it here.
- The default pattern is @samp{"%Embed\n\\(% .*\n\\)*"}, which
- checks for @samp{%Embed} followed by any number of lines beginning
- with @samp{%} and a space. This last is important to make Calc
- consider mode annotations part of the pattern, so that the formula's
- opening delimiter really is sure to follow the pattern.
- X
- @vindex calc-embedded-open-mode
- The @code{calc-embedded-open-mode} variable is a string (not a
- regular expression) which should precede a mode annotation.
- Calc never scans for this string; Calc always looks for the
- annotation itself. But this is the string that is inserted before
- the opening bracket when Calc adds an annotation on its own.
- The default is @samp{"% "}.
- X
- @vindex calc-embedded-close-mode
- The @code{calc-embedded-close-mode} variable is a string which
- follows a mode annotation written by Calc. Its default value
- is simply a newline, @samp{"\n"}. If you change this, it is a
- good idea still to end with a newline so that mode annotations
- will appear on lines by themselves.
- X
- @node Programming, Installation, Embedded Mode, Top
- @chapter Programming
- X
- @noindent
- There are several ways to ``program'' the Emacs Calculator, depending
- on the nature of the problem you need to solve.
- X
- @enumerate
- @item
- @dfn{Keyboard macros} allow you to record a sequence of keystrokes
- and play them back at a later time. This is just the standard Emacs
- keyboard macro mechanism, dressed up with a few more features such
- as loops and conditionals.
- X
- @item
- @dfn{Algebraic definitions} allow you to use any formula to define a
- new function. This function can then be used in algebraic formulas or
- as an interactive command.
- X
- @item
- @dfn{Rewrite rules} are discussed in the section on algebra commands.
- @xref{Rewrite Rules}. If you put your rewrite rules in the variable
- @code{EvalRules}, they will be applied automatically to all Calc
- results in just the same way as an internal ``rule'' is applied to
- evaluate @samp{sqrt(9)} to 3 and so on. @xref{Automatic Rewrites}.
- X
- @item
- @dfn{Lisp} is the programming language that Calc (and most of Emacs)
- is written in. If the above techniques aren't powerful enough, you
- can write Lisp functions to do anything that built-in Calc commands
- can do. Lisp code is also somewhat faster than keyboard macros or
- rewrite rules.
- @end enumerate
- X
- Programming features are available through the @kbd{z} and @kbd{Z}
- prefix keys. New commands that you define are two-key sequences
- beginning with @kbd{z}. Commands for managing these definitions
- use the shift-@kbd{Z} prefix. (The @kbd{Z T} (@code{calc-timing})
- command is described elsewhere; @pxref{Troubleshooting Commands}.
- The @kbd{Z C} (@code{calc-user-define-composition}) command is also
- described elsewhere; @pxref{User-Defined Compositions}.)
- X
- @menu
- * Creating User Keys::
- * Keyboard Macros::
- * Invocation Macros::
- * Algebraic Definitions::
- * Lisp Definitions::
- @end menu
- X
- @node Creating User Keys, Keyboard Macros, Programming, Programming
- @section Creating User Keys
- X
- @noindent
- @kindex Z D
- @pindex calc-user-define
- Any Calculator command may be bound to a key using the @kbd{Z D}
- (@code{calc-user-define}) command. Actually, it is bound to a two-key
- sequence beginning with the @kbd{z} prefix. (Note that the commands
- for programming begin with shift-@kbd{Z}, and your own commands begin
- with unshifted @kbd{z}.)
- X
- The @kbd{Z D} command first prompts for the key to define. For example,
- press @kbd{Z D a} to define the new key sequence @kbd{z a}. You are then
- prompted for the name of the Calculator command that this key should
- run. For example, the @code{calc-sincos} command is not normally
- available on a key. Typing @kbd{Z D s sincos @key{RET}} programs the
- @kbd{z s} key sequence to run @code{calc-sincos}. This definition will remain
- in effect for the rest of this Emacs session, or until you redefine
- @kbd{z s} to be something else.
- X
- You can actually bind any Emacs command to a @kbd{z} key sequence by
- backspacing over the @samp{calc-} when you are prompted for the command name.
- X
- As with any other prefix key, you can type @kbd{z ?} to see a list of
- all the two-key sequences you have defined that start with @kbd{z}.
- Initially, no @kbd{z} sequences (except @kbd{z ?} itself) are defined.
- X
- User keys are typically letters, but may in fact use any key.
- (@key{META}-keys are not permitted, nor are a terminal's special
- function keys which generate multi-character sequences when pressed.)
- You can define different commands on the shifted and unshifted versions
- of a letter if you wish.
- X
- @kindex Z U
- @pindex calc-user-undefine
- The @kbd{Z U} (@code{calc-user-undefine}) command unbinds a user key.
- For example, the key sequence @kbd{Z U s} will undefine the @code{sincos}
- key we defined above.
- X
- @kindex Z P
- @pindex calc-user-define-permanent
- @cindex Storing user definitions
- @cindex Permanent user definitions
- @cindex @file{.emacs} file, user-defined commands
- The @kbd{Z P} (@code{calc-user-define-permanent}) command makes a key
- binding permanent so that it will remain in effect even in future Emacs
- sessions. (It does this by adding a suitable bit of Lisp code into
- your @file{.emacs} file.) For example, @kbd{Z P s} would register
- our @code{sincos} command permanently. If you later wish to unregister
- this command you must edit your @file{.emacs} file by hand.
- (@xref{General Mode Commands}, for a way to tell Calc to use a
- different file instead of @file{.emacs}.)
- X
- The @kbd{Z P} command also saves the user definition, if any, for the
- command bound to the key. After @kbd{Z F} and @kbd{Z C}, a given user
- key could invoke a command, which in turn calls an algebraic function,
- which might have one or more special display formats. A single @kbd{Z P}
- command will save all of these definitions.
- X
- To save a command or function without its key binding (or if there is
- no key binding for the command or function), type @kbd{'} (the apostrophe)
- when prompted for a key. Then, type the function name, or backspace
- to change the @samp{calcFunc-} prefix to @samp{calc-} and enter a
- command name. (If the command you give implies a function, the function
- will be saved, and if the function has any display formats, those will
- be saved, but not the other way around: Saving a function will not save
- any commands or key bindings associated with the function.)
- SHAR_EOF
- true || echo 'restore of calc.texinfo failed'
- fi
- echo 'End of part 51'
- echo 'File calc.texinfo is continued in part 52'
- echo 52 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-